// Oatley 2011 IO

// Load original dataset
clear
use "O2011 IO Rep Data.dta"

// Check MCAR

// (1) Little's MCAR test (highly collinear variables are excluded)
ds, has(type numeric)
keep `r(varlist)'
mcartest `r(varlist)'
// Drop collinear variables
drop yr70
ds, has(type numeric)
keep `r(varlist)'
mcartest `r(varlist)'

// p = 0.0000, thus MCAR can be rejected

// Logit models
clear
use LDC_IO_replication
misstable sum, gen(miss_)
// Start with Table 2, Model 1
logit  miss_newtar  l1polity   l1lnpop  l1gdp_pc   l1ecris2   l1bpc1 l1signed  l1office l1gatt_wto_new l1fiveop l1usheg
// At least one variable is predictive, thus MCAR can be rejected

// REPLICATION
clear
use LDC_IO_replication
summarize
display c(k)
mdesc
tabmiss
codebook country
codebook date
gen inter1= l1polity*l1gatt_wto_new

// Table 2
// Model 1
xi: xtpcse   newtar  l1polity   l1lnpop  l1gdp_pc   l1ecris2   l1bpc1 l1signed  l1office l1gatt_wto_new l1fiveop l1usheg date  i.country, corr(ar1) pairwise
mdesc   newtar  l1polity   l1lnpop  l1gdp_pc   l1ecris2   l1bpc1 l1signed  l1office l1gatt_wto_new l1fiveop l1usheg date country
codebook date if e(sample)
codebook country if e(sample)
outreg2 using o2011_io_long, replace
// Model 2
xi: xtpcse   newtar  l1polity inter1   l1lnpop  l1gdp_pc   l1ecris2   l1bpc1 l1signed  l1office l1gatt_wto_new l1fiveop l1usheg date  i.country, corr(ar1) pairwise
mdesc  newtar  l1polity inter1   l1lnpop  l1gdp_pc   l1ecris2   l1bpc1 l1signed  l1office l1gatt_wto_new l1fiveop l1usheg date country
codebook date if e(sample)
codebook country if e(sample)
outreg2 using o2011_io_long, append excel

// Cannot replicate Table 3 because Sachs-Warner index is not included in replication dataset

// IMPUTATION
// m = 26
clear
use "O2011 IO Imp Data.dta"
summarize

mi import flong, m(imp) id(country date) imp(gatt_wto_new-inter1)

mi stset, clear
sort country date
mi xtset country date

// Table 2
// Model 1
mi estimate, cmdok post: xtpcse   newtar  l1.polityiv_update2   l1.lnpop  l1.gdp_pc   l1.ecris2   l1.bpc1 l1.signed  l1.yrsoffic l1.gatt_wto_new l1fiveop l1.usheg date  i.country, corr(ar1) pairwise
// Model 2
mi estimate, cmdok post: xtpcse   newtar  l1.polity inter1   l1.lnpop  l1.gdp_pc   l1.ecris2   l1.bpc1 l1.signed  l1.yrsoffic l1.gatt_wto_new l1fiveop l1.usheg date  i.country, corr(ar1) pairwise

// m = 5
clear
use "O2011 IO Imp Data 5.dta"
summarize

mi import flong, m(imp) id(country date) imp(gatt_wto_new-inter1)

mi stset, clear
sort country date
mi xtset country date

// Table 2
// Model 1
mi estimate, cmdok post: xtpcse   newtar  l1.polityiv_update2   l1.lnpop  l1.gdp_pc   l1.ecris2   l1.bpc1 l1.signed  l1.yrsoffic l1.gatt_wto_new l1fiveop l1.usheg date  i.country, corr(ar1) pairwise
// Model 2
mi estimate, cmdok post: xtpcse   newtar  l1.polity inter1   l1.lnpop  l1.gdp_pc   l1.ecris2   l1.bpc1 l1.signed  l1.yrsoffic l1.gatt_wto_new l1fiveop l1.usheg date  i.country, corr(ar1) pairwise

// m = 93
clear
use "O2011 IO Imp Data 93.dta"
summarize

mi import flong, m(imp) id(country date) imp(gatt_wto_new-inter1)

mi stset, clear
sort country date
mi xtset country date

// Table 2
// Model 1
mi estimate, cmdok post: xtpcse   newtar  l1.polityiv_update2   l1.lnpop  l1.gdp_pc   l1.ecris2   l1.bpc1 l1.signed  l1.yrsoffic l1.gatt_wto_new l1fiveop l1.usheg date  i.country, corr(ar1) pairwise
// Model 2
mi estimate, cmdok post: xtpcse   newtar  l1.polity inter1   l1.lnpop  l1.gdp_pc   l1.ecris2   l1.bpc1 l1.signed  l1.yrsoffic l1.gatt_wto_new l1fiveop l1.usheg date  i.country, corr(ar1) pairwise

// HD
clear
use "O2011 IO Imp Data HD.dta"
summarize

mi import flong, m(imp) id(country date) imp(gatt_wto_new-inter1)

mi stset, clear
sort country date
mi xtset country date

// Table 2
// Model 1
mi estimate, cmdok post: xtpcse   newtar  l1.polityiv_update2   l1.lnpop  l1.gdp_pc   l1.ecris2   l1.bpc1 l1.signed  l1.yrsoffic l1.gatt_wto_new l1fiveop l1.usheg date  i.country, corr(ar1) pairwise
// Model 2
mi estimate, cmdok post: xtpcse   newtar  l1.polity inter1   l1.lnpop  l1.gdp_pc   l1.ecris2   l1.bpc1 l1.signed  l1.yrsoffic l1.gatt_wto_new l1fiveop l1.usheg date  i.country, corr(ar1) pairwise

// MICE
clear
use "O2011 IO Imp Data MICE.dta"
summarize

mi import flong, m(imp) id(country date) imp(gatt_wto_new-inter1)

sort country date
mi xtset country date

// Table 2
// Model 1
mi estimate, cmdok post: xtpcse   newtar  l1.polityiv_update2   l1.lnpop  l1.gdp_pc   l1.ecris2   l1.bpc1 l1.signed  l1.yrsoffic l1.gatt_wto_new l1fiveop l1.usheg date  i.country, corr(ar1) pairwise
// Model 2
mi estimate, cmdok post: xtpcse   newtar  l1.polity inter1   l1.lnpop  l1.gdp_pc   l1.ecris2   l1.bpc1 l1.signed  l1.yrsoffic l1.gatt_wto_new l1fiveop l1.usheg date  i.country, corr(ar1) pairwise
